package com.un10.qianduan.contorller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import com.un10.entity.User;

import com.un10.service.UserService;
@Controller
public class loginWebContorller {
	@Autowired
	  UserService userService;	
		//锟矫伙拷锟斤拷录
		@RequestMapping("/B/logina")
	public String login(User user,Model model, HttpSession session) {
		//锟斤拷锟斤拷锟矫伙拷锟剿猴拷锟斤拷锟斤拷锟斤拷
		String userName =user.getUserName();	
		String  thecode=user.getThecode();
		System.out.println(userName);
		System.out.println(thecode);
	     User a=userService.finUser(userName, thecode);
	     System.out.println(a);
		if(a !=null ) {
			//锟斤拷锟矫伙拷锟斤拷拥锟絪ession锟斤拷
			session.setAttribute("USER_SESSION",a);

			return  "redirect:index.jsp";
		}
		
		 //锟斤拷锟斤拷撕锟斤拷锟斤拷氩伙拷锟饺�
		model.addAttribute("msg",a);
		return "forward:B/login.jsp";	
	}
		/**
		 * 转锟斤拷锟斤拷Administrator.jsp 页锟斤拷
		 * */
		
		@RequestMapping("B/index")
		public String toAdministrator() {

			return "B/index";
		}
		/**
		 * 锟斤拷全锟剿筹拷
		 * */
		
		@RequestMapping("/logouta")
		public String logout(HttpSession session) {
			//锟斤拷锟絪ession
			session.invalidate();
			 //锟截讹拷锟津到碉拷录页锟斤拷锟斤拷锟阶拷锟斤拷锟�
			 return "forward:B/login.jsp";
		}
}
